package com.wind.trademark.client.controller;


import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wind.trademark.client.model.CtCompany;
import com.wind.trademark.client.model.CtContactor;
import com.wind.trademark.client.service.CompanyService;
import com.wind.trademark.common.exception.TmException;
import com.wind.trademark.common.vo.ComboBean;
import com.wind.trademark.common.vo.PageBean;
import com.wind.trademark.common.vo.PageParam;

@Controller
public class CompanyController {
	@Autowired
	private CompanyService companyService;

	private static final Log log = LogFactory.getLog(CompanyController.class);

	

	@RequestMapping
	public @ResponseBody
	PageBean queryCompany(PageParam pageParam,
			@RequestParam Map<String, Object> params) {

		PageBean pageBean = companyService.queryCompany(pageParam, params);
		return pageBean;
	}

	@RequestMapping
	public @ResponseBody
	CtCompany saveOrUpdateCompany(CtCompany ctCompany) {
		return companyService.saveOrUpdateCompany(ctCompany);

	}

	@RequestMapping
	public @ResponseBody
	CtCompany  loadCompany(Long id) {
		return companyService.getCompany(id);
	}

	@RequestMapping
	public @ResponseBody
	List<CtCompany>  getCtCompanyByCompanyName(@RequestParam("queryParam")String compName) {
		return companyService.getCtCompanyByCompanyName(compName);
	}
	@RequestMapping
	public @ResponseBody
	List<ComboBean>  goolgeCtCompanyByCompanyName(@RequestParam Map<String, Object> params) {
		return companyService.goolgeCtCompanyByCompanyName(params);
	}
	
	
	
	
	
	@RequestMapping
	public @ResponseBody
	PageBean queryContactor(PageParam pageParam,
			@RequestParam Map<String, Object> params) {

		PageBean pageBean = companyService.queryContactor(pageParam, params);
		return pageBean;
	}
	@RequestMapping
	public @ResponseBody
	List<CtContactor> getContactorsByCompId(@RequestParam(required=true)Long compId) {

		return companyService.getContactorsByCompId(compId);
	}
	@RequestMapping
	public @ResponseBody
	CtContactor getDefaultContactorsByCompId(@RequestParam(required=true)Long compId) throws TmException {

		return companyService.getDefaultContactorsByCompId(compId);
	}
	@RequestMapping
	public @ResponseBody
	CtContactor loadContactor(@RequestParam(required=true)Long id) {

		return companyService.loadContactor(id);
	}
	
	@RequestMapping
	public @ResponseBody
	CtContactor saveOrUpdateContactor(CtContactor ctContactor) {
		return companyService.saveOrUpdateContactor(ctContactor);

	}
	@RequestMapping
	public @ResponseBody
	Long[] deleteContactors(Long[] ids) {
		companyService.deleteContactors(Arrays.asList(ids));
		 return ids;
	}
	
	@RequestMapping
	public @ResponseBody
	Long setDefaultContactor(Long id) {
		companyService.setDefaultContactor(id);
		 return id;
	}	
	
}
